package xyz.xtt.exchange.constants;

public enum SortType {
    RANDOM("random"),
    DEFAULT("default"),
    PUT_ON_SELL_DATETIME("putOnSellDatetime"),
    PRICE("price"),
    PRE_SALE("preSale"),
    ON_SALE("onSale"),
    CREATE_DATETIME("createDatetime"),
    END_DATETIME("endDatetime"),
    SELF_OPERATED("selfOperated");

    private final String value;

    SortType(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public static SortType fromValue(String value) {
        if(value.equalsIgnoreCase(RANDOM.getValue())){
            // 随机类型的话  随机返回其他枚举(不能包含随机枚举)
            return SortType.values()[new java.util.Random().nextInt(SortType.values().length - 1) + 1];
        }
        for (SortType sortType : SortType.values()) {
            if (sortType.getValue().equalsIgnoreCase(value)) {
                return sortType;
            }
        }
        return DEFAULT;
    }
}

